package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

public class MovieService {
    public List<String> movieMenu = new ArrayList<String>();

    public MovieService() {
        movieMenu.add("CheckoutMovie");
        movieMenu.add("ReturnMovie");
        movieMenu.add("BackMainmenu");
        movieMenu.add("Quit");
    }

    public String checkoutMovie(int id) {
        String result = "Error input!Please try again!";
        if (id != -1) {
            Movie movie = getMoiveById(id);
            if (movie != null && movie.getStatus() == 0) {
                result = "Thank you! Enjoy the movie.";
                movie.setStatus(1);
            } else {
                result = "That movie is not available.";
            }
        }
        return result;
    }

    public Movie getMoiveById(int id) {
        for (Movie movie : Library.movieList) {
            if (movie.getMovieId() == id) {
                return movie;
            }
        }
        return null;
    }

    public void printAllMovies() {
        System.out.println("*******************************************************************************");
        System.out.println("                                     Movie  List                     ");
        System.out.println("movieId" + "    " + "movieName" + "        " + "year" + "        " + "director" + "    " + "rating" + "    " + "satus");
        for (Movie movie : Library.movieList) {
            if (movie.getStatus() == 0)
                System.out.println(movie.toString());
        }
    }

    public void movieMenu() {
        System.out.print("MovieMenu:*");
        for (String s : movieMenu) {
            System.out.print("   " + s + "   *");
        }
        System.out.println();
        System.out.println("*******************************************************************************");

    }

    public String returnMovie(int movieId) {
        String result = "Error input!Please try again!";
        if (movieId != -1) {
            Movie movie = getMoiveById(movieId);
            if (movie != null && movie.getStatus() == 1) {
                result = "Thank you for returning the movie.";
                movie.setStatus(0);
            } else {
                result = "That is not a valid movie to return.";
            }
        }
        return result;
    }
}
